<?php
include("dbconfig.php");
$db = mysql_pconnect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());

mysql_select_db($database) or die("Error conecting to db.");
mysql_query("SET names UTF8");
$style=$_GET['style'];
if($style==0){
$pid=$_POST['pid'];
$SQL="select count(*) as count from job where pid='-1'";
$result = mysql_query($SQL);
if (!$result) echo "SQLERR".mysql_error(); 
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count=$row[count]+1;
$SQL="Insert into job(pid,cid,name) values('-1','$count','$pid')" ;

$result = mysql_query($SQL);   
if (!$result) echo "SQLERR1".mysql_error(); 
else echo "添加成功";
    
}
else if($style==1){
 $pid=$_POST['pid'];    
 $cid=$_POST['cid'];    
  $SQL="select count(*) as count from job where pid='$pid'";
$result = mysql_query($SQL);
if (!$result) echo "SQLERR".mysql_error(); 
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count=$row[count]+1;
$SQL="Insert into job(pid,cid,name) values('$pid','$count','$cid')" ;

$result = mysql_query($SQL);   
if (!$result) echo "SQLERR1".mysql_error(); 
else echo "添加成功";  
    
}
else if($style==2){
    
$pid=$_POST['dpid'];      
$SQL="delete from job where pid='$pid'or (cid='$pid' and pid='-1') ";
$result = mysql_query($SQL);  
if (!$result) echo "SQLERR1".mysql_error(); 
else echo "删除成功"; 
}
else if($style==3){
$pid=$_POST['dpid'];    
$cid=$_POST['dcid'];  
$SQL="delete from job where pid='$pid' and cid='$cid'";
$result = mysql_query($SQL);
if (!$result) echo "SQLERR1".mysql_error(); 
else echo "删除成功"; 
    }



?>
